<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>话单查询</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div th:replace="~{/ :: #header}"></div>

<h2>话单查询</h2>
<input type="text" id="phone" placeholder="请输入电话号码">
<button onclick="queryRecords()">查询话单</button>

<h3>话单记录</h3>
<div id="call-records"></div>

<script>
  function queryRecords() {
    const phone = $('#phone').val();
    $.get(`/billing/records?phoneNumber=${phone}`, function(data) {
      let recordsHtml = '<ul>';
      data.forEach(record => {
        recordsHtml += `<li>用户名: ${record.userName}, 主叫号码: ${record.callerNumber}, 被叫号码: ${record.calledNumber}, 通话时长: ${record.callDuration}秒</li>`;
      });
      recordsHtml += '</ul>';
      $('#call-records').html(recordsHtml);
    }).fail(function() {
      $('#call-records').html('<p>查询失败，请检查电话号码是否正确。</p>');
    });
  }
</script>
</body>
</html>